package com.shadow.service;

import com.shadow.domain.User;
import com.shadow.repository.UserRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created by qq65827 on 2015/1/26.
 */
@Service
public class UserService extends EntityService<User,UserRepository> {

    private final static Logger logger = LoggerFactory.getLogger(UserService.class);


    public User findUserByName(String username) {
        return repo.findByUsername(username);
    }


    public Boolean isPermit(String username, String password) {
        User user = repo.findByUsername(username);
        logger.info("user is " + user);
        if (user==null){
            return false;
        }
        logger.info(user.getPassword());
        if (user.getPassword().equals(password)) {
            logger.info(user.getPassword());
            return true;
        }
        return false;
    }

    @Resource
    protected UserService userService;

    @Autowired
    protected UserService(UserRepository repo) {
        super(repo);
    }
}
